package com.zjc.yohoshop.adapter;

import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.zjc.yohoshop.R;
import com.zjc.yohoshop.bean.HomeGoodsEntity;
import com.zjc.yohoshop.deamon.NetDeamonCode;
import com.zjc.yohoshop.network.API;


/**
 * 首页适配器
 */
public class HomeGoodsAdapter extends BaseQuickAdapter<HomeGoodsEntity.Values, BaseViewHolder> {


    public HomeGoodsAdapter(int layoutResId) {
        super(layoutResId);
    }

    @Override
    protected void convert(BaseViewHolder helper, HomeGoodsEntity.Values item) {

        ImageView imageView = helper.getView(R.id.iv_home_goods_goods_img_path);
        Glide.with(helper.itemView.getContext()).load(API.BaseUrl + item.goods_img_path).into(imageView);
        helper.setText(R.id.tv_home_goods_goods_name, item.goods_name);
        helper.setText(R.id.tv_home_goods_goods_discount_price, "￥" + item.goods_discount_price);
        helper.setText(R.id.tv_home_goods_goods_original_price, "￥" + item.goods_original_price);
    }
}
/*
 private Context context;
    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
/*
public HomeGoodsAdapter(List<HomeGoodsEntity.Values> data, Context context) {
    super(data);
    this.context = context;
    addItemType(HomeGoodsEntity.Values.banner, R.layout.item_home_banner);
    addItemType(HomeGoodsEntity.Values.recommend, R.layout.item_home_recommend);
    addItemType(HomeGoodsEntity.Values.goods, R.layout.item_home_goods);
}

    @Override
    protected void convert(BaseViewHolder helper, final HomeGoodsEntity.Values item) {
        if (helper.getItemViewType() == HomeGoodsEntity.Values.banner){

            List<String> strings = new ArrayList<>();
            for (HomeBannerEntity.Values values : item.bannerEntity.values){
                strings.add(NetDeamonCode.NETAll + values.recommend_url);
            }
            Banner banner = helper.getView(R.id.ban_home_head);
            banner.setImages(strings);
            banner.setImageLoader(new ImageLoader() {
                @Override
                public void displayImage(Context context, Object path, ImageView imageView) {
                    Glide.with(context).load((String)path).into(imageView);
                }
            });
            banner.isAutoPlay(true);
            banner.setIndicatorGravity(BannerConfig.CENTER);
            banner.setDelayTime(1 * 1500);
            banner.start();

        }else if(helper.getItemViewType() == HomeGoodsEntity.Values.recommend){

            /**
             *
             */
/*
            RecyclerView rv_recommend_url = helper.getView(R.id.rv_recommend_url);
            rv_recommend_url.setLayoutManager(new GridLayoutManager(context, 2, GridLayoutManager.VERTICAL, false));
            rv_recommend_url.setAdapter(new HomeRecommendAdapter(item.recommendEntity.recommend, context));


            /**
             * 横向滑动标题
             */
/*
            RecyclerView rv_category_name = helper.getView(R.id.rv_home_goods_category_name);
            rv_category_name.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
            item.recommendEntity.category.get(0).flag = true;
            HomeCategoryTabAdapter adapter = new HomeCategoryTabAdapter(item.recommendEntity.category);
            rv_category_name.setAdapter(adapter);



        }else if (helper.getItemViewType() == HomeGoodsEntity.Values.goods){
        }
    }

 */
